<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" title="新增会议" back-icon-color='#333333' height="40" :border-bottom="false">
		</u-navbar>
		<u-select v-model="participant" mode="mutil-column-auto" :list="teacher_list" @confirm="ensure"></u-select>
		<u-select v-model="address" mode="mutil-column-auto" :list="address_list" @confirm="commit"></u-select>
		<u-picker mode="time" v-model="conference_time" :params="params" @confirm="submit"></u-picker>
		<u-select v-model="show" mode="single-column" :list="list" @confirm="confirm"></u-select>
		<view class="list">
			<view class="description">
				<text>名称</text>
				<u-input v-model="form.name" style="margin-left:200rpx; width: 200rpx;" :type="type" placeholder="单行输入"
					:border="border" input-align="right" />
			</view>
			<view class="type">
				<text>类型</text>
				<text>{{conference_classify}}</text>
				<text @click="show=true"></text>
			</view>
			<view class="time">
				<view class="top">
					<text>时间</text>
					<text>{{start_date}}&nbsp;{{start_time}}</text>
					<image src="../../static/tupian105.png" mode="widthFix" @click="calendar(1)"></image>
				</view>
				<view class="bottom">
					<text>{{end_date}}&nbsp;{{end_time}}</text>
					<image src="../../static/tupian105.png" mode="widthFix" @click="calendar(2)"></image>
				</view>
			</view>
			<view class="address">
				<text>地点</text>
				<text>{{detail_address}}</text>
				<text @click="address=true">选择地点</text>
			</view>
			<view class="principal">
				<text>负责人</text>
				<text>{{participant_person}}</text>
				<text @click="select_people(1)">选择人员</text>
			</view>
			<view class="participant">
				<text>参与人</text>
				<text>{{person}}</text>
				<text @click="select_people(2)">选择人员</text>
			</view>
			<view class="sign">
				<text>签到</text>
				<view class="toggle" @click="changeBoolen" :id="[boolen==true?'con':'']">
					<text></text>
				</view>
			</view>
		</view>
		<view class="confirm">
			<view class="verify" @click="addMeeting">
				{{verify}}
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../request.js'
	import time from '../../time.js'
	export default {
		data() {
			return {
				type: 'text',
				border: false,
				conference_time: false,
				address: false,
				participant: false,
				participant_num: '',
				content: '',
				conference_classify: "",
				num: '',
				boolen: false,
				verify: '确认',
				show: false,
				list: [{
					label: '科组',
					value: '3'
				}],
				start_date: '',
				start_time: '',
				end_date: '',
				end_time: '',
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				people_list: [],
				id_list: [],
				form: {
					name: '',
					type: '',
					start_time: '',
					end_time: '',
					room_id: '',
					is_sign_in: '',
					is_reply: 1,
					meeting_user: '',
					handle_user_id: ''
				},
				address_list: [],
				teacher_list: [],
				participant_arr: [],
				teacher_arr: [],
				detail_address: '',
				person: '',
				participant_person: '',
			}
		},
		onLoad() {
			this.buildingLists();
			this.groupLists();
		},
		methods: {
			changeBoolen() {
				this.boolen = !this.boolen;
				if (this.boolen) {
					this.form.is_sign_in = 1;
				} else {
					this.form.is_sign_in = 0;
				}

			},
			confirm(e) {
				console.log(e);
				this.conference_classify = e[0].label;
				this.form.type = e[0].label;
			},
			commit(e) {
				console.log(e);
				this.detail_address = `${e[0].label}${e[1].label}${e[2].label}`;
				console.log(e[2].value);
				this.form.room_id = e[2].value;
			},
			ensure(e) {
				console.log(e);
				switch (this.participant_num) {
					case 1:
						this.participant_person = e[1].label;
						this.form.handle_user_id = e[1].value;
						break;
					case 2:
						this.person = e[1].label;
						this.people_list.push(e[1].label);
						this.person = this.people_list.join(',');
						// this.form.meeting_user = e[1].value;
						this.id_list.push(e[1].value);
						break;
				}
			},
			select_people(param) {
				this.participant = true;
				switch (param) {
					case 1:
						this.participant_num = 1;
						break;
					case 2:
						this.participant_num = 2;
						break;
				}
			},
			submit(e) {
				console.log(e);
				let num = '';
				switch (this.num) {
					case 1:
						this.start_date = `${e.year}.${e.month}.${e.day}`;
						this.start_time = `${e.hour}:${e.minute}:${e.second}`;
						num = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`;
						this.form.start_time = Date.parse(new Date(num))/1000;
						break;
					case 2:
						this.end_date = `${e.year}.${e.month}.${e.day}`;
						this.end_time = `${e.hour}:${e.minute}:${e.second}`;
						num = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`;
						this.form.end_time = Date.parse(new Date(num))/1000;
						break;
				}

			},
			calendar(param) {
				this.conference_time = true;
				switch (param) {
					case 1:
						this.num = 1;
						break;
					case 2:
						this.num = 2;
						break;
				}
			},
			addMeeting() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				this.form.meeting_user = this.id_list.join(',');
				request({
					url: base_url + 'teacher/meeting/add',
					data: {
						...this.form
					},
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data);
							_this.$toLink('../school_meeting/school_meeting', {});
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			buildingLists() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'management/building/lists',
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							res.data.data.forEach((item, index) => {
								_this.address_list.push({
									label: item.name,
									value: item.building_id,
									children: [],
								})
								_this.floorLists(item.building_id, index);

							})
							console.log(_this.address_list);
              console.log('的青蛙打网球的气味的');

						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			floorLists(param, param2) {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let building_id = param;
				let indexes = param2;
				let _this = this;
				request({
					url: base_url + 'management/floor/lists',
					method: 'post',
					data: {
						building_id: building_id
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							res.data.data.forEach((item, index) => {
								_this.address_list[param2].children.push({
									label: item.name,
									value: item.floor_id,
									children: [],
								})
								_this.roomLists(building_id, indexes, item.floor_id, index);
							})
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			roomLists(param1, param2, param3, param4) {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'management/room/lists',
					method: 'post',
					data: {
						building_id: param1,
						floor_id: param3
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							res.data.data.forEach(item => {
								if (_this.address_list[param2].children[param4]) {
									_this.address_list[param2].children[param4].children.push({
										label: item.name,
										value: item.room_id,
									})
								}
							})
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			groupLists() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'office/group/lists',
					data: {
						school_district_id: uni.getStorageSync('school_district_id')
					},
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data.data);
							res.data.data.data.forEach((item, index) => {
								_this.teacher_list.push({
									label: item.name,
									value: item.subject_id,
									children: []
								})
								_this.userLists(item.subject_id, index);
							})

						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			userLists(param1, param2) {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'office/group_user/lists',
					data: {
						subject_id: param1
					},
					method: 'post',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data.data);
							res.data.data.data.forEach(item => {
								_this.teacher_list[param2].children.push({
									label: item.teacher_info ? item.teacher_info.full_name : '',
									value: item.teacher_user_id,
								})
							})

						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
		}

	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		height: 100vh;
		background-color: #F2F2F2;

		.list {
			background-color: #fff;
			margin-top: 20rpx;
			width: 710rpx;
			margin-left: 20rpx;
			border-radius: 12rpx;

			.description {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					&:nth-child(1) {
						color: #666666;
						font-size: 26rpx;
					}
				}

			}

			.type {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
					}

					&:nth-child(2) {
						width: 80rpx;
						color: #333333;
						margin-left: 465rpx;
					}

					&:nth-child(3) {
						width: 0rpx;
						margin-left: 20rpx;
						margin-top: 20rpx;
						height: 0rpx;
						border-width: 18rpx 18rpx 18rpx 18rpx;
						border-color: #ccc transparent transparent transparent;
						border-style: solid;
					}
				}
			}

			.time {
				width: 94%;
				margin-left: 3%;
				height: 180rpx;
				border-bottom: 1px solid #F2F2F2;

				.top {
					width: 100%;
					height: 90rpx;
					display: flex;
					justify-content: flex-start;
					align-items: center;

					text {
						font-size: 26rpx;

						&:nth-child(1) {
							color: #666666;
						}

						&:nth-child(2) {
							color: #333333;
							width: 530rpx;
							text-align: right;
						}
					}

					image {
						&:nth-child(3) {
							width: 30rpx;
							margin-left: 50rpx;
						}
					}
				}

				.bottom {
					width: 100%;
					height: 90rpx;
					display: flex;
					justify-content: flex-start;
					align-items: center;

					text {
						font-size: 26rpx;

						&:nth-child(1) {
							width: 580rpx;
							text-align: right;
						}
					}

					image {
						&:nth-child(2) {
							margin-left: 50rpx;
							width: 30rpx;
						}
					}
				}
			}

			.address {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					&:nth-child(1) {
						color: #666666;
						font-size: 26rpx;

					}

					&:nth-child(2) {
						color: #333333;
						font-size: 26rpx;
						width: 478rpx;
						text-align: right;


					}


					&:nth-child(3) {
						width: 107rpx;
						height: 40rpx;
						text-align: center;
						line-height: 40rpx;
						font-size: 20rpx;
						color: #333333;
						background-color: #EDF4FB;
						border: 1rpx solid #ccc;
						border-radius: 5rpx;
						margin-left: 20rpx;
					}
				}
			}

			.principal {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					&:nth-child(1) {
						color: #666666;
						font-size: 26rpx;

					}

					&:nth-child(2) {
						color: #333333;
						font-size: 26rpx;
						width: 454rpx;
						text-align: right;


					}

					&:nth-child(3) {
						width: 107rpx;
						height: 40rpx;
						text-align: center;
						line-height: 40rpx;
						font-size: 20rpx;
						color: #333333;
						background-color: #EDF4FB;
						border: 1rpx solid #ccc;
						border-radius: 5rpx;
						margin-left: 20rpx;
					}
				}
			}

			.participant {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					&:nth-child(1) {
						color: #666666;
						font-size: 26rpx;

					}

					&:nth-child(2) {
						color: #333333;
						font-size: 26rpx;
						width: 454rpx;
						text-align: right;


					}

					&:nth-child(3) {
						width: 107rpx;
						height: 40rpx;
						text-align: center;
						line-height: 40rpx;
						font-size: 20rpx;
						color: #333333;
						background-color: #EDF4FB;
						border: 1rpx solid #ccc;
						border-radius: 5rpx;
						margin-left: 20rpx;
					}
				}
			}

			.sign {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					&:nth-child(1) {
						color: #666666;
						font-size: 26rpx;

					}
				}

				.toggle {
					background-color: #CCCCCC;
					width: 64rpx;
					height: 29rpx;
					margin-left: 535rpx;
					position: relative;
					border-radius: 20rpx;

					text {
						&:nth-child(1) {
							position: absolute;
							width: 26rpx;
							border-radius: 50%;
							background-color: #fff;
							top: 0rpx;
							left: 1rpx;
							height: 26rpx;
						}
					}

				}

				#con {
					background-color: #17CE8B;
					width: 64rpx;
					height: 29rpx;
					margin-left: 520rpx;
					position: relative;
					border-radius: 20rpx;

					text {
						&:nth-child(1) {
							position: absolute;
							width: 26rpx;
							border-radius: 50%;
							background-color: #fff;
							top: 0rpx;
							left: 37rpx !important;
							height: 26rpx;
						}
					}

				}
			}

		}

		.confirm {
			width: 100%;
			margin-top: 100rpx;
			height: 300rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.verify {
				width: 200rpx;
				height: 60rpx;
				border-radius: 50rpx;
				text-align: center;
				line-height: 60rpx;
				background: linear-gradient(to right, #2C78FE, #32B0FF);
				color: #fff;
				font-size: 30rpx;
			}
		}
	}
</style>
